package com.lfsenior.mq;

import redis.clients.jedis.Jedis;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by dlupan on 2018/10/10
 *
 * 消息发布者
 */
public class Publisher {
    private Jedis publisherJedis;
    private String channel;

    public Publisher(Jedis publisherJedis,String channel){
        this.publisherJedis=publisherJedis;
        this.channel=channel;
    }

    public void startPublish(){
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
            while (true){
                System.out.println("请输入发布内容：");
                String msg=bufferedReader.readLine();
                if(!"quit".equals(msg)){
                    publisherJedis.publish(channel, msg);
                }else{
                    break;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
